package com.yn.pet.controller.app;

import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.app.biz.AGenFenceBizService;
import com.yn.pet.controller.pc.request.FenceQueryRequest;
import com.yn.pet.controller.pc.request.FenceSaveRequest;
import com.yn.pet.controller.pc.request.FenceUpdateRequest;
import com.yn.pet.controller.pc.request.PetBindRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Set;

@RestController
@AllArgsConstructor
@RequestMapping("/front/genFence")
@Api(tags = "app端——地理围栏Controller")
@Slf4j
public class AGenFenceController {
    private final AGenFenceBizService genFenceBizService;

    /**
     * 用户添加围栏信息
     * @param request 请求参数
     * @return 响应结果
     */
    @PostMapping("save")
    @ApiOperation("用户添加围栏信息")
    public AjaxResult saveFence(@RequestBody @Validated FenceSaveRequest request) {
        log.info("用户添加围栏信息入参，request:{}",request);
        genFenceBizService.saveFence(request);
        return AjaxResult.success("添加成功");
    }

    /**
     * 用户删除围栏信息
     * @param fenceId 围栏id
     * @return
     */
    @GetMapping("remove")
    @ApiOperation("用户删除围栏信息")
    public AjaxResult removeFence(@RequestParam @NotNull Long fenceId) {
        log.info("用户删除围栏信息,参数 fenceId:{}", fenceId);
        genFenceBizService.removeFence(fenceId);
        return AjaxResult.success("删除成功");
    }

    /**
     * 用户批量删除围栏信息
     * @param fenceIdSet 围栏id集合
     * @return
     */
    @PostMapping("removeBatch")
    @ApiOperation("用户批量删除围栏信息")
    public AjaxResult removeFenceBatch(@RequestBody @NotNull Set<Long> fenceIdSet) {
        log.info("用户批量删除围栏信息,参数 fenceIdSet:{}", fenceIdSet);
        genFenceBizService.removeFenceBatch(fenceIdSet);
        return AjaxResult.success("删除成功");
    }

    /**
     * 用户修改围栏信息
     * @param request 修改围栏信息
     * @return
     */
    @PostMapping("update")
    @ApiOperation("用户修改围栏信息")
    public AjaxResult updateFence(@RequestBody @Validated FenceUpdateRequest request) {
        log.info("用户修改围栏信息入参 request: {}", request);
        genFenceBizService.updateFence(request);
        return AjaxResult.success("操作成功");
    }

    /**
     * 用户分页查询围栏信息
     * @param request 分页查询参数
     * @return IPage<FenceQueryResponse>
     */
    @GetMapping("pageList")
    @ApiOperation("用户分页查询围栏信息")
    public AjaxResult pageList(FenceQueryRequest request) {
        log.info("用户分页查询围栏信息入参 request: {}", request);
        return AjaxResult.success(genFenceBizService.pageList(request));
    }

    /**
     * 查询围栏详情
     * @param fenceId 围栏ID
     * @return
     */
    @GetMapping("detail")
    @ApiOperation("查询围栏详情")
    public AjaxResult queryById(@RequestParam("fenceId") @NotNull Long fenceId) {
        log.info("查询围栏详情入参 fenceId: {}", fenceId);
        return AjaxResult.success(genFenceBizService.queryById(fenceId));
    }

    /**
     * 是否启用围栏
     * @param fenceId 围栏ID
     * @param status 状态 0:禁用,1:启用
     * @return
     */
    @PostMapping("isUse/{fenceId}/{status}")
    @ApiOperation("是否启用围栏")
    public AjaxResult isUse(@PathVariable @NotNull Long fenceId,
                            @PathVariable @NotNull @ApiParam("0:禁用,1:启用") Integer status) {
        log.info("是否启用围栏入参: fenceId: {},status:{}", fenceId, status);
        genFenceBizService.isUse(fenceId, status);
        return AjaxResult.success("设置成功");
    }

}
